package net.qiqb.spring.domain.event;

import net.qiqb.core.domain.event.DomainEventPublisher;
import net.qiqb.core.domain.event.DomainEvent;
import net.qiqb.core.domain.event.DomainEventPersistence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

public class LocalDomainPublisher implements DomainEventPublisher {

    private DomainEventPersistence domainEventPersistence;

    private ApplicationContext applicationContext;

    @Override
    public void publishEvent(DomainEvent event) {
        // 发布
        applicationContext.publishEvent(event.getPayload());
    }

    @Autowired
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    @Autowired
    public void setDomainEventPersistence(DomainEventPersistence domainEventPersistence) {
        this.domainEventPersistence = domainEventPersistence;
    }
}
